package com.mentaleye.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.dal.dao.PropertyDao;
import com.mentaleye.dal.model.Property;
import com.mentaleye.dal.model.PropertyExample;
import com.mentaleye.dal.model.PropertyExample.Criteria;
import com.mentaleye.service.PropertyService;

@Service
public class PropertyServiceImpl implements PropertyService{
	
	@Autowired  private PropertyDao dataDao;
	
	@Override
	public boolean insertRecord(Property record) {
		return this.dataDao.insertRecord(record);
	}
	
	@Override
	public boolean insertByList(List<Property> recordList) {
		return this.dataDao.insertByList(recordList);
	}

	@Override
	public boolean updateRecord(Property record) {
		return this.dataDao.updateRecord(record);
	}

	@Override
	public boolean updateRecordBySelective(Property record) {
		PropertyExample example=new PropertyExample();
		Criteria criteria = example.createCriteria();
		criteria.andPropertyIdEqualTo(record.getPropertyId());
		return this.dataDao.updateRecordBySelective(example, record);
	}
	
	@Override
	public boolean deleteByList(List<String> idList) {
		PropertyExample example=new PropertyExample();
		Criteria criteria = example.createCriteria();
		criteria.andPropertyIdIn(idList);
		return this.dataDao.deleteByExample(example);
	}

	@Override
	public List<Property> getList() {
		PropertyExample example=new PropertyExample();
		return this.dataDao.getListByExample(example);
	}

	@Override
	public List<Property> getListByKeys(List<String> idList) {
		PropertyExample example=new PropertyExample();
		Criteria criteria = example.createCriteria();
		criteria.andPropertyIdIn(idList);
		return this.dataDao.getListByExample(example);
	}
	
	@Override
	public Property getRecordByKey(String propertyId) {
		Property property=null;
		PropertyExample example=new PropertyExample();
		Criteria criteria = example.createCriteria();
		criteria.andPropertyIdEqualTo(propertyId);
		List<Property> recordList = this.dataDao.getListByExample(example);
		if(!recordList.isEmpty()){
			property=recordList.get(0);
		}
		return property;
	}

	@Override
	public List<Map<String, Object>> getListByMap(Map<String, Object> map) {
		return this.dataDao.getListByMap(map);
	}
}
